package com.ruoyi.activity.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.activity.domain.CfGroupPurchase;
import com.ruoyi.activity.service.ICfGroupPurchaseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 信息发布Controller
 * 
 * @author tzg
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/InformationDelivery")
public class CfGroupPurchaseController extends BaseController
{
    @Autowired
    private ICfGroupPurchaseService cfGroupPurchaseService;

    /**
     * 查询信息发布列表
     */
    @RequiresPermissions("activity:InformationDelivery:list")
    @GetMapping("/list")
    public TableDataInfo list(CfGroupPurchase cfGroupPurchase)
    {
        startPage();
        List<CfGroupPurchase> list = cfGroupPurchaseService.selectCfGroupPurchaseList(cfGroupPurchase);
        return getDataTable(list);
    }

    /**
     * 查询商户列表
     */
    @RequiresPermissions("activity:InformationDelivery:list")
    @GetMapping("/publisherList")
    public TableDataInfo publisherList()
    {
        List<CfGroupPurchase> list = cfGroupPurchaseService.selectPublisherList();
        return getDataTable(list);
    }

    /**
     * 导出信息发布列表
     */
    @RequiresPermissions("activity:InformationDelivery:export")
    @Log(title = "信息发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CfGroupPurchase cfGroupPurchase)
    {
        List<CfGroupPurchase> list = cfGroupPurchaseService.selectCfGroupPurchaseList(cfGroupPurchase);
        ExcelUtil<CfGroupPurchase> util = new ExcelUtil<CfGroupPurchase>(CfGroupPurchase.class);
        util.exportExcel(response, list, "信息发布数据");
    }

    /**
     * 获取信息发布详细信息
     */
    @RequiresPermissions("activity:InformationDelivery:query")
    @GetMapping(value = "/{gpId}")
    public AjaxResult getInfo(@PathVariable("gpId") String gpId)
    {
        return success(cfGroupPurchaseService.selectCfGroupPurchaseByGpId(gpId));
    }

    /**
     * 新增信息发布
     */
    @RequiresPermissions("activity:InformationDelivery:add")
    @Log(title = "信息发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CfGroupPurchase cfGroupPurchase)
    {
        return toAjax(cfGroupPurchaseService.insertCfGroupPurchase(cfGroupPurchase));
    }

    /**
     * 修改信息发布
     */
    @RequiresPermissions("activity:InformationDelivery:edit")
    @Log(title = "信息发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CfGroupPurchase cfGroupPurchase)
    {
        return toAjax(cfGroupPurchaseService.updateCfGroupPurchase(cfGroupPurchase));
    }

    /**
     * 删除信息发布
     */
    @RequiresPermissions("activity:InformationDelivery:remove")
    @Log(title = "信息发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gpIds}")
    public AjaxResult remove(@PathVariable String[] gpIds)
    {
        return toAjax(cfGroupPurchaseService.deleteCfGroupPurchaseByGpIds(gpIds));
    }
}
